package com.prs.crm.action.hr.report;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.action.ReportAction;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.report.ExportConfig;
import com.prs.crm.report.ReportCell;
import com.prs.crm.report.ReportTable;
import com.prs.crm.service.hr.PersonService;

public class PersonReportAction extends ReportAction{

	private static final long serialVersionUID = 1L;
	
	private PersonService personService;

	private PaginationSupport pagination;

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public PersonService getPersonService() {
		return personService;
	}

	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}

	public PaginationSupport getPagination() {
		return pagination;
	}

	
	@Action("listReportPerson")
	public String listReportPerson()
	{
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				Person.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getPersonService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}
	
	@Action(value="exportPersonReport", results = { @Result(name = "success"
		,type="stream",params={"contentType","${contentType}","inputName","inputStream"
		,"bufferSize","1024","contentDisposition","filename=${outfileName}"}) })
	public String reportPerson()
	{
		ReportTable table = new ReportTable("人员报表");
		table.addCell(new ReportCell("序号","id"));
		table.addCell(new ReportCell("人员编码","code"));
		table.addCell(new ReportCell("登录名","loginCode"));
		table.addCell(new ReportCell("真实姓名","resume.name"));
		table.addCell(new ReportCell("部门","dept.name"));
		table.addCell(new ReportCell("职位","role.name"));
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(Person.class);
		//this.setOutFilePath(this.getReportService().reportPDF(criteria, table, new ExportConfig()));
		this.setOutFilePath(this.getReportService().report(criteria, table, new ExportConfig(),this.getExportType()));
		return SUCCESS;
	}
}
